package com.dataease.indicatorqa.controller;

import com.dataease.indicatorqa.assistant.IndicatorQaAgent;
import com.dataease.indicatorqa.model.ChatForm;
import com.dataease.indicatorqa.model.IndicatorQuery;
import com.dataease.indicatorqa.model.IndicatorResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@Tag(name = "指标问答系统")
@RestController
@RequestMapping("/api/indicator")
@CrossOrigin
public class IndicatorQaController {

    @Autowired
    private IndicatorQaAgent indicatorQaAgent;

    @Operation(summary = "指标问答")
    @PostMapping(value = "/query", produces = "application/json")
    public IndicatorResult query(@RequestBody IndicatorQuery query) {
        return indicatorQaAgent.queryIndicator(query.getQuestion(), query.getContext());
    }

    @Operation(summary = "流式问答")
    @PostMapping(value = "/chat", produces = "text/stream;charset=utf-8")
    public Flux<String> chat(@RequestBody ChatForm chatForm) {
        return indicatorQaAgent.chat(chatForm.getMemoryId(), chatForm.getMessage());
    }
}